package com.zkingsoft.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.matrix.core.constance.MatrixConstance;
import com.matrix.core.constance.SystemErrorCode;
import com.matrix.core.exception.GlobleException;
import com.matrix.core.pojo.PaginationVO;
import com.matrix.core.tools.ModelUtils;
import com.matrix.core.tools.UUIDUtil;
import com.matrix.core.tools.WebUtil;
import com.zkingsoft.bean.BizOrder;
import com.zkingsoft.bean.BizUser;
import com.zkingsoft.common.bean.SysUsers;
import com.zkingsoft.dao.BizOrderDao;
import com.zkingsoft.redis.RedisUserLoginUtils;
import com.zkingsoft.service.BizOrderService;

/**
 * @description service接口实现类(订单信息) 
 * @author 何明
 * @date 2018-05-23 00:08
 */
@Service
public class  BizOrderServiceImpl implements  BizOrderService{

	
	@Autowired
	private BizOrderDao bizOrderDao;

	
	@Override
	public int add(BizOrder bizOrder){
		// 设置基本字段信息
		return bizOrderDao.insert(bizOrder);
		
	}
	
	@Override
	public int batchAdd(List<BizOrder>  bizOrderList) {
		//这里没有做基本字段的设置，如有需要请自己实现	
		int num = 0;
		int c = 10000;
		int size = bizOrderList.size()/c + 1;
		for(int i=0; i<size; i++) {
			int begin = i*c;
			int end = (i+1)*c;
			end = end >= bizOrderList.size() ? bizOrderList.size() : end;
			List<BizOrder> insertList = bizOrderList.subList(begin, end);
			num += bizOrderDao.batchInsert(insertList);
		}
		return num;
		
	}
	
	
   	
    @Override
	public int modifyByMap(BizOrder oldBizOrder
	,BizOrder newBizOrder){
	
		Map<String, Object> modifyMap = null;
		try {
			if (!ModelUtils.isModified(oldBizOrder, newBizOrder)) {
				return MatrixConstance.DML_SUCCESSS;
			}
			modifyMap = ModelUtils.comparePojo2Map(oldBizOrder, newBizOrder);
		} catch (Exception e) {
			throw new GlobleException(SystemErrorCode.DATA_UPDATE_FAIL, e, newBizOrder);
		}
		if (modifyMap.size() > 0) {
			modifyMap.put("orderId", oldBizOrder.getOrderId());
			bizOrderDao.updateByMap(modifyMap);
		}
		return MatrixConstance.DML_SUCCESSS;
	}
	
	@Override
	public int modifyByModel(BizOrder bizOrder){
	
		return bizOrderDao.updateByModel(bizOrder);
	
	}
	
	
	
	@Override
	public int remove(List<String> list){
	
		return bizOrderDao.deleteByIds(list);
	
	}

	@Override
	public int removeById(String orderId){
	
		return bizOrderDao.deleteById(orderId);
	
	}
	
	@Override
	public int removeByModel(BizOrder bizOrder){
	
		return bizOrderDao.deleteByModel(bizOrder);
	
	}
	
	
	@Override
	public List<BizOrder> findInPage(BizOrder bizOrder,  PaginationVO pageVo){
	
		return bizOrderDao.selectInPage(bizOrder , pageVo);
	
	}
	
	@Override
	public List<BizOrder> findByModel(BizOrder bizOrder){
	
		return bizOrderDao.selectByModel(bizOrder);
	
	}
	
	@Override
	public int  findTotal(BizOrder bizOrder){
	
		return bizOrderDao.selectTotalRecord(bizOrder);
	
	}
	
	@Override
	public BizOrder  findById(String orderId){
	
		return bizOrderDao.selectById(orderId);
	
	}

   	
	
	
}